package br.com.sovi.resources.ponto;

import java.util.Date;
import java.util.List;

import org.openinsula.vulcano.orm.command.DaoCommand;
import org.openinsula.vulcano.orm.dao.query.DaoQuery;
import org.openinsula.vulcano.orm.dao.query.builder.DaoSelect;

import br.com.sovi.persistence.Dispositivo;
import br.com.sovi.persistence.Ponto;

public class FindPontosByEmpresaAndData extends DaoCommand<List<Ponto>> {

	private final String serial;

	private final Date dataInicial;

	private final Date dataFinal;

	public FindPontosByEmpresaAndData(String serial, Date dataInicial, Date dataFinal) {
		this.serial = serial;
		this.dataInicial = dataInicial;
		this.dataFinal = dataFinal;
	}

	@Override
	public List<Ponto> execute() {
		DaoQuery<Dispositivo> dispositivoQuery = new DaoSelect<Dispositivo>().all().from(Dispositivo.class).eq(
				"serial", serial).limit(1).toQuery();

		Dispositivo dispositivo = dao.findUnique(dispositivoQuery);

		DaoQuery<Ponto> query = new DaoSelect<Ponto>().all().from(Ponto.class).eq("dispositivo", dispositivo).between(
				"data", dataInicial, dataFinal).toQuery();

		return dao.find(query);
	}

}
